home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / MemInit.c,v < prev    next >
Encoding:
Text File  |  1991-12-03  |  2.8 KB  |  131 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.1.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     88.05.20.15.49.17;  author ouster;  state Exp;
  11. branches 1.1.1.1;
  12. next     ;
  13.  
  14. 1.1.1.1
  15. date     91.12.02.20.36.40;  author kupfer;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24.  
  25. 1.1
  26. log
  27. @Initial revision
  28. @
  29. text
  30. @/* 
  31.  * MemInit.c --
  32.  *
  33.  *    Source code for "MemInit", a library procedure used internally
  34.  *    by the storage allocator.  Also contains static variables shared
  35.  *    between the allocator routines.  See memInt.h for overall
  36.  *    information about how the allocator works.
  37.  *
  38.  * Copyright 1985, 1988 Regents of the University of California
  39.  * Permission to use, copy, modify, and distribute this
  40.  * software and its documentation for any purpose and without
  41.  * fee is hereby granted, provided that the above copyright
  42.  * notice appear in all copies.  The University of California
  43.  * makes no representations about the suitability of this
  44.  * software for any purpose.  It is provided "as is" without
  45.  * express or implied warranty.
  46.  */
  47.  
  48. #ifndef lint
  49. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  50. #endif not lint
  51.  
  52. #include "memInt.h"
  53.  
  54. /*
  55.  * ----------------------------------------------------------------------------
  56.  *
  57.  * MemInit --
  58.  *
  59.  *      Initializes the dynamic storage allocator.
  60.  *
  61.  * Results:
  62.  *      None.
  63.  *
  64.  * Side effects:
  65.  *      The storage allocation structures are initialized.
  66.  *
  67.  * ----------------------------------------------------------------------------
  68.  */
  69.  
  70. void
  71. MemInit()
  72. {
  73.     int i;
  74.  
  75.     memInitialized = TRUE;
  76.  
  77.     /*
  78.      * Clear out all of the bins.
  79.      */
  80.  
  81.     for (i = 0; i < BIN_BUCKETS; i++) {
  82.     memFreeLists[i] = NOBIN;
  83.     mem_NumBlocks[i] = 0;
  84. #ifdef MEM_TRACE
  85.     mem_NumBinnedAllocs[i] = 0;
  86. #endif
  87.     }
  88.  
  89.     /*
  90.      * Mark all the small buckets except 0 as available for binning.
  91.      * Don't mark 0:  it's used as a special trigger in malloc to
  92.      * return NULL when allocating zero bytes without affecting
  93.      * the inner loop for binned allocations.
  94.      */
  95.  
  96.     for (i = 1; i < SMALL_BUCKETS; i++) {
  97.     memFreeLists[i] = (Address) NULL;
  98.     }
  99.  
  100.     /* 
  101.      * Initialize the large-object free list with two blocks that
  102.      * mark its beginning and end.
  103.      */
  104.  
  105.     memFirst = MemChunkAlloc(MIN_REGION_SIZE);
  106.     memLast = memFirst + MIN_REGION_SIZE - sizeof(AdminInfo);
  107.     SET_ADMIN(memFirst, MARK_FREE(memLast - memFirst));
  108.     SET_ADMIN(memLast, MARK_DUMMY(0));
  109.     memCurrentPtr    = memFirst;
  110.     memLargestFree    = 0;
  111.     memBytesFreed    = 0;
  112.     mem_NumLargeBytes    = MIN_REGION_SIZE;
  113.  
  114. #ifdef MEM_TRACE
  115.     mem_NumLargeAllocs    = 0;
  116.     mem_NumLargeLoops    = 0;
  117. #endif
  118. }
  119. @
  120.  
  121.  
  122. 1.1.1.1
  123. log
  124. @Initial branch for Sprite server.
  125. @
  126. text
  127. @d20 1
  128. a20 1
  129. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/MemInit.c,v 1.1 88/05/20 15:49:17 ouster Exp $ SPRITE (Berkeley)";
  130. @
  131.